package com.itheima.mycollection;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionDemo4 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = new Student("张三",23);
        Student stu2 = new Student("张四",24);
        Student stu3 = new Student("张无忌",25);

        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        Iterator<Student> iterator = list.iterator();

        while(iterator.hasNext()){
            Student student = iterator.next();
            System.out.println("student = " + student);
        }
        System.out.println("============");
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println("student = " + student);
        }
        System.out.println("============");

        for (Student student : list) {
            System.out.println("student = " + student);
        }
    }
}
